<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:include page="/WEB-INF/views/layouts/header.jsp" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 网站地址
String netPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<style>
.yhgltable ul li span.current {
	font-weight: bold
}

.chooseColumn {
	width: 196px;
	height: 30px;
	line-height: 30px;
	color: #666;
	border: 1px solid #BBB;
}

.chooseColumn option {
	height: 30px;
}

.next,.prev {
	filter: Alpha(opacity =50);
	-moz-opacity: .1;
	opacity: 0.5;
}
</style>
<script type="text/javascript">
		// 页码
	var pageNo = 1;
	// 总页数
	var pageSum = 1;
	$(function(){
	refreshSuggestions();
	});
	// 默认翻页是对于filterArticles结果集来说
	function initPageButton(){
		if(pageSum>1){
			if(pageNo==1){
				//默认不可用
				$("[name=prevButton]").addClass("prev")
				$("[name=nextButton]").removeClass("next");
			} else if(pageNo==pageSum){
				//下翻页不可用
				$("[name=nextButton]").addClass("next")
				$("[name=prevButton]").removeClass("prev");
				//alert($("[name=prevButton]").attr("class"));
			} else {
				// 上下翻页都可用
				$("[name=prevButton]").removeClass("prev");
				$("[name=nextButton]").removeClass("next");
				
			}
		} else {
			$("[name=prevButton]").addClass("prev");
			$("[name=nextButton]").addClass("next");
		}
	};
	// 搜索
	var searchText = "";
	function clickSearch(){
		pageNo = 1;
		pageSum = 1;
		searchText = $("[name=searchText]").val()?encodeURIComponent($("[name=searchText]").val()):"";
		// 让ie不读取缓存
		$.ajaxSetup ({ cache: false });
		$(".userContent").load("<%=basePath%>suggestion/searchSuggestion?searchText="+searchText+"&pageNo="+pageNo,function(response,status){
      		if (status=="success"){
      			var intPageSum = parseInt($(response).find("input[name='pageSum']").val());
      			if(intPageSum>=1){
      				pageSum = intPageSum;
      			}
      			initPageButton();
      		}
        });
	};
	
	function blurSearch(){
		clickSearch();
	}

	

	/**
	 *把指定的一组checkbox所选的值构造为逗号分隔的字符串
	 */
	function getAllValue(group_box) {
		var boxes = document.getElementsByName(group_box);
		var values = "";
		for (var i = 0; i < boxes.length; i++) {
			if (boxes[i].checked) {
				values += boxes[i].value + ",";
			}
		}
		if (values.length > 0) {
			values = values.substring(0, values.length - 1);
		}
		return values;
	};
	// 删除
	function toDelete(){
		var operatorIds = getAllValue("group_box");
		if(!operatorIds){
			alert("请选择需要删除的栏目！");
			return;
		}

		if(confirm("确认删除？")){
			$.ajax({
			  url: "<%=basePath%>suggestion/toDelete",
			  type:"POST",
			  contentType:"application/x-www-form-urlencoded; charset=utf-8",
			  data: "strSuggestion="+operatorIds,
			  dataType: 'text',
			  success: function(data) {
				 var jsonobj=eval('('+data+')');
				 if(jsonobj.state==='1'){
					refreshSuggestions();
					alert(jsonobj.result);
				 } else if(jsonobj.state==='0'){
					 alert(jsonobj.result);
				 }
			  },
			  error: function(XMLHttpRequest, textStatus, errorThrown) {
					 alert("删除失败！");
			  }
			});
		}
	};
	
	function toUpdate(intId){
		var url = "<%=basePath%>suggestion/update?intSuggestionID="+intId;
		var HTML = '<div class="Popup">';
		HTML += '<div class="Popupheader"><a node-type="close" href="#"><img src="<%=basePath%>images/Popupclose01.png" width="28" height="28"></a></div>';
		HTML += '<div class="Popup_A"><div class="Popup_A_1">';
				HTML += '<div class="Popup_title"><h2>互动答疑</h2></div>';
				HTML += '<iframe width="100%" height="400" src="'+ url +'" scrolling="no" frameborder="0"></iframe>';
				HTML += '</div></div>'
				HTML += '<div class="Popupfoot"><img src="<%=basePath%>images/Popupbg01_footer.png" width="550" height="15"></div></div>';
		$.dialog({skin:false,content:HTML});
	};

	
	// 局部刷新
	function refreshSuggestions(){
	    searchText = $("[name=searchText]").val()?encodeURIComponent($("[name=searchText]").val()):"";
	    $.ajaxSetup ({ cache: false });
	    $(".userContent").load("<%=basePath%>suggestion/searchSuggestion?searchText="+searchText+"&pageNo="+pageNo,function(response,status){
      		if (status=="success"){
      			var intPageSum = parseInt($(response).find("input[name='pageSum']").val());
      			if(intPageSum>=1){
      			pageSum = intPageSum;
      			}
      			initPageButton();
      		}
        });
	};
		// 下一页
	function nextPage(){
		if(pageNo<pageSum){
			pageNo ++;
			initPageButton();
			refreshSuggestions();
		}
	};
	
	function prevPage(){
		
		if(pageNo>1){
			pageNo --;
			initPageButton();
			refreshSuggestions();
		}
	};
	

</script>
<!--中间部分开始-->
<div class="main">
	<!-- 左侧 -->
	<div class="rightblock">
		<p class="shadow"></p>
		<div class="content">
			
			<div class="mainblock">
				<div class="tabA">
					<h1>
						<a href="<%=basePath%>suggestion/operate" style="color:#585858">问题管理</a>
					</h1>
				</div>
				<div class="lineone mt10">
					<span> <img name="prevButton" src="<%=basePath%>images/back.png"
						class="prev linkhand" style="cursor:pointer;"
						onclick="prevPage();"> <img name="nextButton"
						src="<%=basePath%>images/next.png" class="next linkhand"
						style="cursor:pointer;" onclick="nextPage();" /> </span>
					<div class="btn">
						<a href="javascript:void(0)" onclick="toDelete()"><img src="<%=basePath%>images/del.gif" />删除</a>
					</div>
					<div class="search">
						<select  name="searchText" style="color:#666" onblur="blurSearch()">
						  <option value ="">请选择</option>
						  <option value ="0">未回答</option>
						  <option value ="1">已回答</option>
						</select> 
							<img src="<%=basePath%>images/search.png" onclick="clickSearch()" style="cursor: pointer" />
					</div>
				</div>

				<table border="0" cellpadding="0" cellspacing="0"
					class="yhgltable mt10" style="width:93%">
					<tr>
						<td rowspan="2" class="userContent" valign="top">
						    <script type="text/javascript">
						    	// 禁止ie读取缓存
									$.ajaxSetup ({ 
									cache: false
									 });
			            		$(".userContent").load("<%=basePath%>suggestion/showSuggestions");
			            	</script>
			            </td>
					</tr>
				</table>
				
			</div>
		</div>

	</div>
</div>
<!--中间部分结束-->
<!--底部开始-->
<jsp:include page="/WEB-INF/views/layouts/footer.jsp" />
<!--底部结束-->
</body>
</html>
